package ldh.common.testui.handle;

import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TabPane;
import javafx.scene.control.TreeView;
import ldh.common.testui.constant.TreeNodeType;
import ldh.common.testui.handle.impl.ExportDataTreeNodeService;
import ldh.common.testui.handle.impl.ParamTreeNodeService;
import ldh.common.testui.handle.impl.ProjectTreeNodeService;
import ldh.common.testui.handle.impl.SqlTreeNodeService;
import ldh.common.testui.model.TreeNode;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TreeNodeHandle {

    private TreeView<TreeNode> treeView;
    private TabPane tabPane;
    private ContextMenu contextMenu;
    private List<MenuItem> menuItems;

    private Map<TreeNodeType, ITreeNodeService> treeNodeMap = new ConcurrentHashMap<>();

    public TreeNodeHandle(TreeView<TreeNode> treeView, TabPane tabPane) {
        this.tabPane = tabPane;
        this.treeView = treeView;
        this.contextMenu = new ContextMenu();

        treeView.setContextMenu(contextMenu);

        initTreeNodeMap();
    }

    private void initTreeNodeMap() {
        treeNodeMap.put(TreeNodeType.Param, new ParamTreeNodeService(treeView, tabPane, contextMenu, TreeNodeType.Param));
        treeNodeMap.put(TreeNodeType.Node, new ProjectTreeNodeService(treeView, tabPane, contextMenu, TreeNodeType.Node));
        treeNodeMap.put(TreeNodeType.ExportData, new ExportDataTreeNodeService(treeView, tabPane, contextMenu, TreeNodeType.ExportData));
        treeNodeMap.put(TreeNodeType.SqlCheckData, new SqlTreeNodeService(treeView, tabPane, contextMenu, TreeNodeType.SqlCheckData));
    }


}
